<!DOCTYPE html>
<html lang="en" xmlns:sa="http://www.thymeleaf.org/extras/sa-token"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>移动备案管理</title>
    <!--公共模块-->
    <div th:replace="~{layout}"></div>
</head>
<body>
<div class="panel panel-default operation_mobile" hidden>
    <div class="panel-heading title"></div>
    <div class="layui-card-body">
        <form class="layui-form" action="" lay-filter="info" style="width: 900px;margin-top: 10px">
            <input name="id" hidden/>
            
            <!-- 第一行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>公司名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="companyName" placeholder="请输入公司名称" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>局数据端口</label>
                        <div class="layui-input-block">
                            <input type="text" name="bureauDataPort" placeholder="请输入局数据端口" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第二行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>码号使用范围</label>
                        <div class="layui-input-block">
                            <input type="text" name="codeUsageRange" placeholder="请输入码号使用范围" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>接入省</label>
                        <div class="layui-input-block">
                            <input type="text" name="accessProvince" placeholder="请输入接入省" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第三行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>接入地市</label>
                        <div class="layui-input-block">
                            <input type="text" name="accessCity" placeholder="请输入接入地市" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>真实发送端口号</label>
                        <div class="layui-input-block">
                            <input type="number" name="realSendPort" placeholder="请输入真实发送端口号" autocomplete="off" class="layui-input" lay-verify="required|number" min="1" max="65535">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第四行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>真实发送端口号的单位名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="realSendPortCompany" placeholder="请输入单位名称" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>单位证件类型</label>
                        <div class="layui-input-block">
                            <input type="text" name="realSendPortCompanyCertType" placeholder="请输入单位证件类型" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第五行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>单位证件号码</label>
                        <div class="layui-input-block">
                            <input type="text" name="realSendPortCompanyCertNumber" placeholder="请输入统一社会信用代码(18位)" autocomplete="off" class="layui-input" lay-verify="required|uscc" maxlength="18">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>法人名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="legalPersonName" placeholder="请输入法人名称" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第六行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>企业签名</label>
                        <div class="layui-input-block">
                            <input type="text" name="enterpriseSignature" placeholder="请输入企业签名" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>APP名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="appName" placeholder="请输入APP名称" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第七行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>责任人(含法人)姓名</label>
                        <div class="layui-input-block">
                            <input type="text" name="responsiblePersonName" placeholder="请输入责任人姓名" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>责任人证件类型</label>
                        <div class="layui-input-block">
                            <input type="text" name="responsiblePersonCertType" placeholder="请输入责任人证件类型" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第八行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>责任人证件号码</label>
                        <div class="layui-input-block">
                            <input type="text" name="responsiblePersonCertNumber" placeholder="请输入责任人证件号码" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>经办人姓名</label>
                        <div class="layui-input-block">
                            <input type="text" name="agentName" placeholder="请输入经办人姓名" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第九行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>经办人证件名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="agentCertName" placeholder="请输入经办人证件名称" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>经办人证件号码</label>
                        <div class="layui-input-block">
                            <input type="text" name="agentCertNumber" placeholder="请输入经办人证件号码" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第十行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>授权开始时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="authStartTime" id="authStartTime" placeholder="请选择授权开始时间" autocomplete="off" class="layui-input" lay-verify="required" readonly>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>授权到期时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="authEndTime" id="authEndTime" placeholder="请选择授权到期时间" autocomplete="off" class="layui-input" lay-verify="required" readonly>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第十一行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>短信端口服务类型</label>
                        <div class="layui-input-block">
                            <input type="text" name="smsPortServiceType" placeholder="请输入短信端口服务类型" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">广告营销类短信行业类别</label>
                        <div class="layui-input-block">
                            <input type="text" name="adMarketingSmsCategory" placeholder="请输入广告营销类短信行业类别" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第十二行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">客户是否需要自行扩展</label>
                        <div class="layui-input-block">
                            <select name="needSelfExtend">
                                <option value="">请选择</option>
                                <option value="是">是</option>
                                <option value="否">否</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否免企业签名</label>
                        <div class="layui-input-block">
                            <select name="freeEnterpriseSignature">
                                <option value="">请选择</option>
                                <option value="是">是</option>
                                <option value="否">否</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第十三行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>短信端口具体用途</label>
                        <div class="layui-input-block">
                            <textarea name="smsPortPurpose" placeholder="请输入短信端口具体用途" class="layui-textarea" lay-verify="required"></textarea>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>运营商接入机房位置与设备位置</label>
                        <div class="layui-input-block">
                            <textarea name="carrierRoomLocation" placeholder="请输入运营商接入机房位置与设备位置" class="layui-textarea" lay-verify="required"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第十四行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>短信端口企业商接入机房位置与设备位置</label>
                        <div class="layui-input-block">
                            <textarea name="smsPortEnterpriseRoomLocation" placeholder="请输入短信端口企业商接入机房位置与设备位置" class="layui-textarea" lay-verify="required"></textarea>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">内容模板实例</label>
                        <div class="layui-input-block">
                            <textarea name="contentTemplateExample" placeholder="请输入内容模板实例" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第十五行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">合同协议文本</label>
                        <div class="layui-input-block">
                            <textarea name="contractAgreementText" placeholder="请输入合同协议文本" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>客户类型</label>
                        <div class="layui-input-block">
                            <input type="text" name="customerType" placeholder="请输入客户类型" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第十六行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>经办人手机号</label>
                        <div class="layui-input-block">
                            <input type="text" name="agentPhone" placeholder="请输入经办人手机号" autocomplete="off" class="layui-input" lay-verify="required|phone">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>责任人(含法人)手机号</label>
                        <div class="layui-input-block">
                            <input type="text" name="responsiblePersonPhone" placeholder="请输入责任人手机号" autocomplete="off" class="layui-input" lay-verify="required|phone">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第十七行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>签名核验类别</label>
                        <div class="layui-input-block">
                            <input type="text" name="signatureVerifyType" placeholder="请输入签名核验类别" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>所属客户</label>
                        <div class="layui-input-block">
                            <input type="text" name="belongingCustomer" placeholder="请输入所属客户" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 第十八行 -->
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            <select name="status">
                                <option value="0">待提交</option>
                                <option value="1">已提交</option>
                                <option value="2">已备案</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">保存</button>
                    <button class="layui-btn layui-btn-primary" id="btn_cancel">返回</button>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="mobile_table_div">
    <div id="searchParam">
        <form class="layui-form layui-form-pane" action="">
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <input type="text" name="companyName" class="layui-input" autocomplete="off" placeholder="请输入公司名称">
                </div>
                <div class="layui-input-inline">
                    <input type="text" name="appName" class="layui-input" autocomplete="off" placeholder="请输入APP名称">
                </div>
                <div class="layui-input-inline layui-form">
                    <select name="status">
                        <option value="">请选择状态</option>
                        <option value="0">待提交</option>
                        <option value="1">已提交</option>
                        <option value="2">已备案</option>
                    </select>
                </div>
                <div class="layui-input-inline">
                    <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                </div>
            </div>
        </form>
    </div>
    
    <table class="layui-hide" id="mobile_table" lay-filter="mobile_table"></table>
</div>

<!-- 隐藏的文件上传输入框 -->
<input type="file" id="importFile" accept=".xlsx,.xls" style="display: none;">

<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="addNewMobile">新增</button>
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="importData">导入</button>
        <button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="refreshData">刷新</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary" lay-event="batchToPending">批量待提交</button>
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="batchToSubmitted">批量已提交</button>
        <button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="batchToFiled">批量已备案</button>
    </div>
</script>

<script type="text/html" id="tool">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="toPending">待提交</a>
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="toSubmitted">已提交</a>
    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="toFiled">已备案</a>
</script>

<script type="text/html" id="statusTpl">
    {{# if(d.status == 0) { }}
        <span class="layui-badge layui-bg-orange">待提交</span>
    {{# } else if(d.status == 1) { }}
        <span class="layui-badge layui-bg-blue">已提交</span>
    {{# } else if(d.status == 2) { }}
        <span class="layui-badge layui-bg-green">已备案</span>
    {{# } else { }}
        <span class="layui-badge layui-bg-gray">未知</span>
    {{# } }}
</script>

<script th:inline="none">
    layui.use(['table', 'form', 'layer', 'laydate'], function () {
        var table = layui.table;
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;

        // 自定义验证规则
        form.verify({
            uscc: function(value, item) {
                if (value && value.length > 18) {
                    return '统一社会信用代码不能超过18位';
                }
            }
        });

        var tableIns = table.render({
            elem: '#mobile_table'
            , contentType: 'application/json'
            , page: true
            , url: ctx + 'mobileRecord/listByPage'
            , method: 'POST'
            , parseData: function (res) {
                return {
                    "code": res.code,
                    "msg": res.msg,
                    "count": res.data ? res.data.total : 0,
                    "data": res.data ? res.data.records : []
                }
            }
            , cols: [
                [
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'companyName', title: '公司名称', width: 200},
                    {field: 'appName', title: 'APP名称', width: 150},
                    {field: 'realSendPort', title: '真实发送端口号', width: 150},
                    {field: 'responsiblePersonName', title: '责任人', width: 100},
                    {field: 'status', title: '状态', width: 100, templet: '#statusTpl'},
                    {field: 'createTime', title: '创建时间', width: 160},
                    {field: 'updateTime', title: '更新时间', width: 160},
                    {title: '操作', width: 350, toolbar: '#tool', fixed: 'right'}
                ]
            ]
            , toolbar: '#toolbar'
        });

        // 初始化日期选择器
        laydate.render({
            elem: '#authStartTime'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#authEndTime'
            , type: 'datetime'
        });

        // 工具栏事件
        table.on('toolbar(mobile_table)', function (obj) {
            switch (obj.event) {
                case 'addNewMobile':
                    $(".mobile_table_div").hide();
                    $(".operation_mobile").show();
                    $(".title").html("新增移动备案");
                    form.val('info', {
                        "id": "",
                        "companyName": "",
                        "bureauDataPort": "",
                        "codeUsageRange": "",
                        "accessProvince": "",
                        "accessCity": "",
                        "realSendPort": "",
                        "realSendPortCompany": "",
                        "realSendPortCompanyCertType": "",
                        "realSendPortCompanyCertNumber": "",
                        "legalPersonName": "",
                        "enterpriseSignature": "",
                        "appName": "",
                        "responsiblePersonName": "",
                        "responsiblePersonCertType": "",
                        "responsiblePersonCertNumber": "",
                        "agentName": "",
                        "agentCertName": "",
                        "agentCertNumber": "",
                        "authStartTime": "",
                        "authEndTime": "",
                        "smsPortServiceType": "",
                        "adMarketingSmsCategory": "",
                        "needSelfExtend": "",
                        "freeEnterpriseSignature": "",
                        "smsPortPurpose": "",
                        "carrierRoomLocation": "",
                        "smsPortEnterpriseRoomLocation": "",
                        "contentTemplateExample": "",
                        "contractAgreementText": "",
                        "customerType": "",
                        "agentPhone": "",
                        "responsiblePersonPhone": "",
                        "signatureVerifyType": "",
                        "belongingCustomer": "",
                        "status": "0"
                    });
                    
                    // 新增时移除真实发送端口号的只读属性
                    $('input[name="realSendPort"]').removeAttr('readonly');
                    
                    // 重新渲染表单
                    form.render();
                    break;
                case 'importData':
                    document.getElementById('importFile').click();
                    break;
                case 'refreshData':
                    tableIns.reload();
                    break;
                case 'batchToPending':
                    batchUpdateStatus(table.checkStatus('mobile_table').data, 0);
                    break;
                case 'batchToSubmitted':
                    batchUpdateStatus(table.checkStatus('mobile_table').data, 1);
                    break;
                case 'batchToFiled':
                    batchUpdateStatus(table.checkStatus('mobile_table').data, 2);
                    break;
            }
        });

        // 行工具事件
        table.on('tool(mobile_table)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'del':
                    layer.confirm('确定删除这条记录吗？', {icon: 3, title: '提示'}, function (index) {
                        layer.close(index);
                        CoreUtil.sendDelete(ctx + 'mobileRecord/delete/' + data.id, null, function (res) {
                            layer.msg(res.msg);
                            tableIns.reload();
                        });
                    });
                    break;
                case 'edit':
                    $(".mobile_table_div").hide();
                    $(".operation_mobile").show();
                    $(".title").html("编辑移动备案");
                    getMobileDetail(data.id);
                    break;
                case 'toPending':
                    updateStatus(data.id, 0, '待提交');
                    break;
                case 'toSubmitted':
                    updateStatus(data.id, 1, '已提交');
                    break;
                case 'toFiled':
                    updateStatus(data.id, 2, '已备案');
                    break;
            }
        });

        // 获取详情
        var getMobileDetail = function (id) {
            CoreUtil.sendGet(ctx + "mobileRecord/detail/" + id, null, function (res) {
                if (res.code === 0) {
                    form.val('info', res.data);
                    
                    // 编辑时设置真实发送端口号为只读
                    $('input[name="realSendPort"]').attr('readonly', true);
                } else {
                    layer.msg('获取详情失败：' + res.msg);
                }
            });
        };

        // 更新状态
        var updateStatus = function (id, status, statusName) {
            var url = '';
            switch (status) {
                case 0:
                    url = 'mobileRecord/status/toPending/' + id;
                    break;
                case 1:
                    url = 'mobileRecord/status/toSubmitted/' + id;
                    break;
                case 2:
                    url = 'mobileRecord/status/toFiled/' + id;
                    break;
            }
            
            CoreUtil.sendPost(ctx + url, null, function (res) {
                layer.msg(res.msg);
                tableIns.reload();
            });
        };

        // 批量更新状态
        var batchUpdateStatus = function (data, status) {
            var ids = [];
            for (var i = 0; i < data.length; i++) {
                ids.push(data[i].id);
            }

            if (ids.length === 0) {
                layer.msg('请选择要批量操作的记录');
                return;
            }

            var statusName = '';
            switch (status) {
                case 0:
                    statusName = '待提交';
                    break;
                case 1:
                    statusName = '已提交';
                    break;
                case 2:
                    statusName = '已备案';
                    break;
            }

            layer.confirm('确定要将选中的 ' + ids.length + ' 条记录设置为 "' + statusName + '" 吗？', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                CoreUtil.sendPost(ctx + 'mobileRecord/status/batchUpdateStatus', {ids: ids, status: status}, function (res) {
                    layer.msg(res.msg);
                    tableIns.reload();
                });
            });
        };

        // 返回按钮
        $("#btn_cancel").click(function () {
            $(".mobile_table_div").show();
            $(".operation_mobile").hide();
            return false;
        });

        // 监听提交
        form.on('submit(submit)', function (data) {
            var params = data.field;
            
            if (params.id === undefined || params.id === null || params.id === "") {
                // 新增
                CoreUtil.sendPost(ctx + "mobileRecord/add", params, function (res) {
                    layer.msg(res.msg);
                    $(".mobile_table_div").show();
                    $(".operation_mobile").hide();
                    tableIns.reload();
                });
            } else {
                // 编辑
                CoreUtil.sendPost(ctx + "mobileRecord/update", params, function (res) {
                    layer.msg(res.msg);
                    $(".mobile_table_div").show();
                    $(".operation_mobile").hide();
                    tableIns.reload();
                });
            }
            return false;
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            tableIns.reload({
                page: {
                    curr: 1
                }
                , where: data.field
            });
            return false;
        });

        // 文件导入处理
        document.getElementById('importFile').onchange = function (e) {
            var file = e.target.files[0];
            if (!file) {
                return;
            }

            var formData = new FormData();
            formData.append('file', file);

            layer.load(1, {shade: [0.3, '#000']});

            fetch(ctx + 'mobileRecord/import', {
                method: 'POST',
                body: formData
            }).then(response => response.json()).then(result => {
                layer.closeAll('loading');
                if (result.code === 0) {
                    layer.msg('导入成功', {icon: 1});
                    tableIns.reload();
                } else {
                    layer.msg('导入失败：' + result.msg, {icon: 2});
                }
            }).catch(err => {
                layer.closeAll('loading');
                layer.msg('导入失败：' + err.message, {icon: 2});
            });

            e.target.value = '';
        };

        // 企业统一社会信用代码输入限制：只允许输入数字和大写字母
        $('input[name="realSendPortCompanyCertNumber"]').on('input', function() {
            var value = $(this).val();
            // 转换为大写并移除非数字和非字母字符
            value = value.toUpperCase().replace(/[^0-9A-Z]/g, '');
            $(this).val(value);
        });

        // 真实发送端口号输入限制：只允许输入数字
        $('input[name="realSendPort"]').on('input', function() {
            var value = $(this).val();
            // 移除非数字字符
            value = value.replace(/[^\d]/g, '');
            // 限制范围在1-65535
           // if (value && parseInt(value) > 99999999999999999999999) {
                
           // }
            $(this).val(value);
        });
    });
</script>

</body>
</html>


